package db

import (
	"TD-UI/api"
	v1 "TD-UI/api/v1"
	"TD-UI/internal/model"
	"TD-UI/internal/service"
	"context"
	"github.com/gogf/gf/v2/util/gconv"
)

type ControllerDb struct {
}

func NewV1() api.IDbV1 {
	return &ControllerDb{}
}

func (c *ControllerDb) CreateDb(ctx context.Context, req *v1.DbReq) (res *v1.DbRes, err error) {
	tData := model.DbReq{}
	err = gconv.Struct(req, &tData)
	if err != nil {
		panic(err)
	}
	result, err := service.Db().CreateDb(ctx, tData)
	gconv.Struct(result, &res)
	return

}

func (c *ControllerDb) Dbddl(ctx context.Context, req *v1.DbDdlReq) (res *v1.DbRes, err error) {
	tData := model.DbDdlReq{}
	err = gconv.Struct(req, &tData)
	if err != nil {
		panic(err)
	}
	result, err := service.Db().Dbddl(ctx, tData)
	gconv.Struct(result, &res)
	return
}

func (c *ControllerDb) DbDel(ctx context.Context, req *v1.DbDelReq) (res *v1.DbRes, err error) {
	tData := model.DbDelReq{}
	err = gconv.Struct(req, &tData)
	if err != nil {
		panic(err)
	}
	result, err := service.Db().DbDel(ctx, tData)
	gconv.Struct(result, &res)
	return
}
